import { defineConfig,loadEnv } from 'vite'
import { resolve } from 'path';

import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx';
// https://vitejs.dev/config/
import { createHtmlPlugin } from 'vite-plugin-html'


export default defineConfig(({ command, mode })=>{
  const env = loadEnv(mode, process.cwd(), '')

  return{
    plugins: [vue(),vueJsx(),
      createHtmlPlugin({
        inject:{
          data:{
            title:env.VITE_APP_NAME,
            description:env.VITE_APP_DESCRIPTION,
            keyWords:env.VITE_APP_KEYWORDS,
            icoUrl:env.VITE_APP_ICON
          }
        }
      })
    ],
    resolve: {
      alias: [
        {
          find: '@',
          replacement: resolve(__dirname, './src'),
        },
        {
          find: 'assets',
          replacement: resolve(__dirname, './src/assets'),
        },
      ],
      extensions: ['.ts', '.js'],
    },
    esbuild: {
      jsxFactory: 'h',
      jsxFragment: 'Fragment'
    },
    server:{
      port:8002,
      proxy: {
        '/api': {
          target: 'http://localhost:9002/qcy-blog',
          changeOrigin: true,
          secure: true,
          rewrite: (path) => path.replace(/^\/api/, ''),
        }
      }
    }
  }
})
